<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
    const obj1 = {
        name: 'zhangsan',
        age: 18,
        children: [
            {
                name: 'lisi',
                age: 18,
                children: [
                    {
                        name: 'li5',
                        age: 18,
                        children: [
                            {
                                name: 'xiao5',
                                age: 11,
                            },
                            {
                                name: 'xiao3',
                                age: 14,
                            },
                        ],
                    },
                    {
                        name: 'li6',
                        age: 18,
                    },
                ],
            },
            {
                name: 'wangwu',
                age: 19,
            },
            {
                name: 'liuliu',
                age: 20,
                children: [
                    {
                        name: 'liu7',
                        age: 11,
                    },
                ],
            },
        ],
    };
    // 正则表达式
    // function getColumnValuesFromJSONArr(jsonArr, attrName) {
    //     const jsonStr = JSON.stringify(jsonArr);
    //     let attrValArr = [];
    //     const regExp = new RegExp('"' + attrName + '":"(.*?)"', 'mg');
    //     while (regExp.test(jsonStr)) {
    //         attrValArr.push(RegExp.$1);
    //     }
    //     return attrValArr;
    // }
    // console.log(getColumnValuesFromJSONArr(p, "name"));
    function logNames(obj) {
        console.log(obj.name);
        for (const child of obj.children || []) {
            logNames(child);
        }
    }
    logNames(obj1);
    </script>
</body>
</html>